package cn.caijiapeng.spt.bean;

public final class Operate<T> {
	private boolean isOk;
	private T value;
	private String message;
	
	private Operate() {
        this.value = null;
    }
	
	private Operate(boolean isOk, T value, String message) {
		this.isOk = isOk;
        this.value = value;
        this.message = message;
    }
	
	public static <T> Operate<T> ok(T value) {
        return new Operate<T>(true, value, null);
    }
	
	public static <T> Operate<T> fail() {
        return new Operate<T>(false, null, null);
    }
	
	public static <T> Operate<T> fail(String message) {
        return new Operate<T>(false, null, message);
    }
	
	public boolean isOk() {
		return isOk;
	}
	
	public boolean notOk() {
		return !isOk;
	}
	
	public T get() {
		return value;
	}
	
	public String getMessage() {
		return message;
	}
}